-- NERDTree
-- open a NERDTree automatically when vim starts up
-- autocmd VimEnter * NERDTree
-- place the cursor in the editor
vim.cmd [[autocmd VimEnter * wincmd w]]
vim.cmd [[autocmd StdinReadPre * let s:std_in=1]]
vim.cmd [[autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif]]
-- close vim when the only left open is a NERDTree
vim.cmd [[autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif]]
-- If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
vim.cmd [[autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 | let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif]]

-- toggle nerdtree
local default_opts = {noremap = true, silent = true}
vim.api.nvim_set_keymap('', '<leader>t', ':NERDTreeToggle<CR>', default_opts)
vim.api.nvim_set_keymap('', '<leader>l', ':NERDTreeFind<CR>', default_opts)

-- " Change default arrows
-- " let g:NERDTreeDirArrowExpandable = '📁'
-- " let g:NERDTreeDirArrowCollapsible = '📂'
vim.g.NERDTreeDirArrowExpandable = '+'
vim.g.NERDTreeDirArrowCollapsible = '-'
vim.g.NERDTreeGitStatusIndicatorMapCustom = {
	Modified  = "✹",
	Staged    = "✚",
	Untracked = "✭",
	Renamed   = "➜",
	Unmerged  = "═",
	Deleted   = "✖",
	Dirty     = "✗",
	Clean     = "✔︎",
	Ignored   = '☒',
	Unknown   = "?"
}

-- " display row number in NERDTree
-- " let NERDTreeShowLineNumbers = 1
-- " set width
-- " let NERDTreeWinSize=20
-- vim.cmd "let NERDTreeIgnore = []"
vim.g.NERDTreeIgnore = {'\\.pyc$', '\\.pyo$', '\\~$', '__pycache__$[[dir]]', '\\.swp$', 'node_modules'}

vim.g.NERDTreeFileExtensionHighlightFullName = 1
vim.g.NERDTreeExactMatchHighlightFullName = 1
vim.g.NERDTreePatternMatchHighlightFullName = 1

